package cn.gogpay.dcb.ixc.cloud.auth.config;

import cn.gogpay.dcb.ixc.cloud.auth.interceptor.AuthRequestPreHandler;
import cn.gogpay.dcb.ixc.cloud.auth.listener.CmdRunner;
import cn.gogpay.dcb.ixc.cloud.auth.utils.AuthContextStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author: YinHeng
 * @date: 2021/2/7 11:05
 * @description: Bean注册
 */
public class CloudAuthConfig {

    private static final Logger logger = LoggerFactory.getLogger(CloudAuthConfig.class);

    @Bean
    public AuthRequestPreHandler authHandlerInterceptor() {
        return new AuthRequestPreHandler();
    }

    @Bean
    public AuthWebMvcConfig authWebMvcConfig(AuthRequestPreHandler authRequestPreHandler) {
        return new AuthWebMvcConfig(authRequestPreHandler);
    }

    @Bean(name = "authTemplate")
    @LoadBalanced
    public RestTemplate restTemplate() {
        logger.info("cloud-auth authTemplate 初始化...");
        return new RestTemplate();
    }


    @Bean(name = "cmdRunner")
    public CmdRunner cmdRunner() {
        logger.info("cloud-auth 监听器初始化...");
        return new CmdRunner();
    }

    @Bean
    public AuthContextStore authContextStore() {
        return new AuthContextStore();
    }
}
